/*
*  数据库连接配置
* */

const config = require('../common/config');

// 导入mongo模块
const mongoose = require("mongoose");
mongoose.Promise = Promise;

mongoose.connect(config.dbUrl, {
  promiseLibrary: global.Promise,
  useNewUrlParser: true,
  useCreateIndex: true,
  useUnifiedTopology: true
});
//连接数据库
const db = mongoose.connection;

db.on('error', () => {
  console.log('数据库连接出错');
});

db.once('open', () => {
  console.log('数据库连接成功');
});

db.on("disconnected", () => {
  console.log('数据库断开连接');
});

module.exports = db;
